home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / programacao / visual / perl.exe / {app} / Webroot / cgi-bin / loan.pl < prev    next >
Encoding:
Perl Script  |  2003-01-11  |  3.3 KB  |  110 lines

  1. #!perl
  2.  
  3. use CGI qw/:standard :html3/;
  4.  
  5. # this defines the contents of the fill out forms
  6. # on each page.
  7. @PAGES = ('Personal Information','References','Assets','Review','Confirmation');
  8. %FIELDS = ('Personal Information' => ['Name','Address','Telephone','Fax'],
  9.            'References'           => ['Personal Reference 1','Personal Reference 2'],
  10.            'Assets'               => ['Savings Account','Home','Car']
  11.            );
  12. # accumulate the field names into %ALL_FIELDS;
  13. foreach (values %FIELDS) {
  14.     grep($ALL_FIELDS{$_}++,@$_);
  15. }
  16.  
  17.  
  18. # figure out what page we're on and where we're heading.
  19. $current_page = calculate_page(param('page'),param('go'));
  20. $page_name = $PAGES[$current_page];
  21.  
  22. print_header();
  23. print_form($current_page)         if $FIELDS{$page_name};
  24. print_review($current_page)       if $page_name eq 'Review';
  25. print_confirmation($current_page) if $page_name eq 'Confirmation';
  26. print end_html;
  27.  
  28. # CALCULATE THE CURRENT PAGE
  29. sub calculate_page {
  30.     my ($prev,$dir) = @_;
  31.     return 0 if $prev eq '';        # start with first page
  32.     return $prev + 1 if $dir eq 'Submit Application';
  33.     return $prev + 1 if $dir eq 'Next Page';
  34.     return $prev - 1 if $dir eq 'Previous Page';
  35. }
  36.  
  37. # PRINT HTTP AND HTML HEADERS
  38. sub print_header {
  39.     print header,
  40.     start_html("Your Friendly Family Loan Center"),
  41.     h1("Your Friendly Family Loan Center"),
  42.     h2($page_name);
  43. }
  44.  
  45. # PRINT ONE OF THE QUESTIONNAIRE PAGES
  46. sub print_form {
  47.     my $current_page = shift;
  48.     print "Please fill out the form completely and accurately.",
  49.        start_form,
  50.        hr;
  51.     draw_form(@{$FIELDS{$page_name}});
  52.     print hr;
  53.     print submit(-name=>'go',-value=>'Previous Page')
  54.         if $current_page > 0;
  55.     print submit(-name=>'go',-value=>'Next Page'),
  56.        hidden(-name=>'page',-value=>$current_page,-override=>1),
  57.        end_form;
  58. }
  59.  
  60. # PRINT THE REVIEW PAGE
  61. sub print_review {
  62.     my $current_page = shift;
  63.     print "Please review this information carefully before submitting it. ",
  64.        start_form;
  65.     my (@rows);
  66.     foreach $page ('Personal Information','References','Assets') {
  67.         push(@rows,th({-align=>LEFT},em($page)));
  68.         foreach $field (@{$FIELDS{$page}}) {
  69.             push(@rows,
  70.                  TR(th({-align=>LEFT},$field),
  71.                     td(param($field)))
  72.                  );
  73.             print hidden(-name=>$field);
  74.         }
  75.     }
  76.     print table({-border=>1},caption($page),@rows),
  77.        hidden(-name=>'page',-value=>$current_page,-override=>1),
  78.        submit(-name=>'go',-value=>'Previous Page'),
  79.        submit(-name=>'go',-value=>'Submit Application'),
  80.        end_form;
  81. }
  82.  
  83. # PRINT THE CONFIRMATION PAGE
  84. sub print_confirmation {
  85.     print "Thank you. A loan officer will be contacting you shortly.",
  86.        p,
  87.        a({-href=>'../source.html'},'Code examples');
  88. }
  89.  
  90.  
  91. # CREATE A GENERIC QUESTIONNAIRE
  92. sub draw_form {
  93.     my (@fields) = @_;
  94.     my (%fields);
  95.     grep ($fields{$_}++,@fields);
  96.     my (@hidden_fields) = grep(!$fields{$_},keys %ALL_FIELDS);
  97.     my (@rows);
  98.     foreach (@fields) {
  99.         push(@rows,
  100.              TR(th({-align=>LEFT},$_),
  101.                 td(textfield(-name=>$_,-size=>50))
  102.                 )
  103.              );
  104.     }
  105.     print table(@rows);
  106.  
  107.     foreach (@hidden_fields) {
  108.         print hidden(-name=>$_);
  109.     }
  110. }